@extends('layout.adminlayout')
@section('css')
 <script src="/admin/js/metisMenu.min.js"></script>
 <script src="/admin/js/custom.js"></script>
 <link href="/admin/css/area_info.css" rel="stylesheet">
 <link href="/admin/css/custom.css" rel="stylesheet">
 <link href="/admin/css/add_manage.css" rel="stylesheet">
 <script type="text/javascript" src="http://api.map.baidu.com/getscript?v=2.0&ak=U25vSd26q851cuSCjMCXuFkYYemWxvRs&services=&t=20170707103901"></script>
@endsection
@section('content')
<div class="forms">
      <div class=" form-grids row form-grids-right"> 
       <div class="widget-shadow " data-example-id="basic-forms"> 
        <div class="form-title"> 
         <h4>添加建筑 :</h4> 
        </div> 
        <div class="form-body"> 
         <form action="/admin/building/store" method="post" class="form-horizontal" onsubmit="return fun4()" style="position:relative">
          {{csrf_field()}}
          <div class="form-group"> 
           <label for="inputEmail3" class="col-sm-1 control-label" style="width: 33%;top: 30px;float: left;"> 所属区域 : </label> 
           <li class="area_info"> 
            <div class="col-sm-6"> 
             <select name="area" id="area" class="form-control1" ;="" style="float: right;width: 70%;">
              <option value="0">请选择区域</option>
              @if($area != null)
               @foreach($area as $v)
                <option value="{{$v['a_id']}}">{{$v['a_name']}}</option>
               @endforeach
              @endif
             </select>
            </div>
           </li>
          </div> 
          <div class="form-group"> 
           <label for="inputPassword3" class="col-sm-1 control-label" style="width: 33%;top: 30px;float: left;"> 建筑名称 : </label> 
           <div class="col-sm-6"> 
            <input type="text" class="form-control" name="building" id="building" placeholder="建筑名称" style="float: right;width: 70%;" /> 
           </div> 
          </div> 
          <div class="form-group"> 
           <label for="inputPassword3" class="col-sm-1 control-label" style="width: 33%;top: 30px;float: left;"> 总层数 : </label> 
           <div class="col-sm-6"> 
            <input type="text" class="form-control" name="total" id="total" placeholder="总层数" style="float: right;width: 70%;" /> 
           </div> 
          </div> 
          <div class="form-group"> 
           <label for="inputPassword3" class="col-sm-1 control-label" style="width: 33%;top: 30px;float: left;"> 最低层 : </label> 
           <div class="col-sm-6"> 
            <input type="text" class="form-control" name="low" id="low" placeholder="最低层数" style="float: right;width: 70%;" /> 
           </div> 
          </div> 
          <div class="form-group"> 
           <label for="inputPassword3" class="col-sm-1 control-label" style="width: 33%;top: 30px;float: left;"> 最高层 : </label> 
           <div class="col-sm-6"> 
            <input type="text" class="form-control" name="high" id="high" placeholder="最高层数" style="float: right;width: 70%;" /> 
           </div> 
          </div> 
          <div class="form-group"> 
           <label for="inputPassword3" class="col-sm-1 control-label" style="width: 33%;top: 30px;float: left;"> 经度 : </label> 
           <div class="col-sm-6" id="longitude"> 
            <input type="text" class="form-control" name="long" placeholder="113.381500" readonly="" style="float: right;width: 70%;" /> 
           </div> 
          </div> 
          <div class="form-group"> 
           <label for="inputPassword3" class="col-sm-1 control-label" style="width: 33%;top: 30px;float: left;"> 纬度 : </label> 
           <div class="col-sm-6" id="latitude"> 
            <input type="text" class="form-control" name="lat" placeholder="34.435400" readonly="" style="float: right;width: 70%;" /> 
            <li class="area_info" id="addinput"></li> 
           </div> 
          </div> 
          <div class="form-group"> 
           <label for="inputPassword3" class="col-sm-1 control-label" style="margin-top: 6px; width: 33%;float: left;"> 负责人 : </label> 
           <div class="col-sm-6"> 
            <input type="text" class="form-control" name="manage" placeholder="负责人" id="manage" style="width: 31%;float: left;margin-left: -3px;" /> 
            <button type="button" class="btn btn-default" id="add" style="float: right">添加</button> 
           </div> 
          </div> 
          <div class="form-group"> 
           <label for="inputPassword3" class="col-sm-1 control-label"> </label> 
           <div class="col-sm-6" id="latitude"> 
            <ul id="ul" style="border:0px; width:100%; padding:0px; background:none; height:34px;"> 
            </ul> 
           </div> 
          </div> 
          <div id="allmap"  style="width: 100%; height: 20em; margin-bottom: 2em; overflow: hidden; position: relative; z-index: 0; background-color: rgb(243, 241, 236); color: rgb(0, 0, 0); text-align: left;background: red;margin-top: -3em"> 
          </div> 
          <div class="col-sm-offset-2"> 
           <button type="button" class="btn btn-default" id="sub" style="margin-top: -24px;margin-left: -22px; width: 90%">提交</button> 
          </div> 
         </form> 
        </div> 
       </div> 
      </div> 
     </div> 
<script>
    //提交表单
    $('#sub').click(function () {
        var area = $('#area').val();
        var building = $('#building').val();
        var total = $('#total').val();
        var low = $('#low').val();
        var high = $('#high').val();
        var longitude = $('input[name=long]').val();
        var lat = $('input[name=lat]').val();
        var manage = new Array();
        $('.mng').each(function () {
            manage.push($(this).html());
        });
        if(area != 0 && building !='' && total != '' && low != '' && high != '' && longitude != '' && lat != ''){
            $.ajax({
                type:'post',
                url:'/admin/building/create',
                async:false,
                data:{
                    "_token": $("input[name=_token]").val(),
                    'area':area,
					'building':building,
					'total':total,
					'low':low,
					'high':high,
					'long':longitude,
					'lat':lat,
                    'manage':manage
                },
                dataType:'json',
                success:function (data) {
                    if(data.status == '1'){
                        location.href = '/admin/building/index';
                    }
                    return false;
                }
            })
        }else{
            alert('信息填写不完整或经纬度填写不合法')
            return false;
        }
    });
</script>
@endsection
@section('lastjs')
 <script src="/admin/js/map_new.js"></script>
 <script src="/admin/js/add_manage.js"></script>
@endsection